package com.qfedu.edu.controller.normal;

import com.qfedu.edu.pojo.User;
import com.qfedu.edu.result.R;
import com.qfedu.edu.service.impl.UserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "用户管理",description = "用户模块")
public class UserNormalController {
    @Autowired
    private UserService userService;

    @GetMapping("/normal/list")
    public R list() {
        return R.ok().data("userList", userService.findAll());
    }

    @GetMapping("/normal/listById")
    public R listById(Integer id) {
        return R.ok().data("user", userService.findUserById(id));
    }

    @PostMapping("/normal/addUser")
    public R addUser(@RequestBody User user) {
        userService.addUser(user);
        return R.ok();
    }
    @PostMapping("/normal/updateUser")
    public R updateUser(@RequestBody User user) {
        userService.updateUser(user);
        return R.ok();
    }
    @GetMapping("/normal/deleteById")
    public R deleteById(Integer id) {
        userService.deleteById(id);
        return R.ok();
    }
}
